<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登陆页面</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">
</head>
<body>
    <div class="nav">
        网页聊天
    </div>
    <div class="login-container">
        <div class="login-dialog">
            <h3>登录</h3>
            <div class="row">
                <span>用户名</span>
                <input type="text" id="username">
            </div>
            <div class="row">
                <span>密码</span>
                <input type="text" id="password">
            </div>
            <div class="row">
                <button id="submit">登录</button>
            </div>
            <div class="regist">
                <a href="registry.html">注册</a>
            </div>
        </div>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
    <script>
        let submitBtn = document.querySelector("#submit");
        submitBtn.onclick = function () {
            let username = document.querySelector("#username").value;
            let password = document.querySelector("#password").value;
            if (username == '' || password == '') {
                alert("您输入的用户名或者密码为空！");
                return;
            }

            $.ajax({
                type: 'post',
                url: 'user/login',
                data: {
                    username: username,
                    password: password
                },
                success: function (result) {
                    if (result.status == 200) {
                        alert('登录成功');
                    }else {
                        alert('登录失败');
                        $("#username").val('');
                        $("#password").val('')
                    }
                },
            })
        }
    </script>
</body>
</html>